import React from 'react'


class Car extends React.Component {
  state = {
      image: 'https://robohash.org/123?set=set5',
      count: 1,
      title: '这是一件商品'

  }
  render() {
    const {  image, count, title } = this.state
    return (
      <div>
        <dl>
          <dt>
            <img src={image} alt="" />
          </dt>
          <dd>
            <h3>{title}</h3>
            <p>
              <button onClick={() => this.setState({ count: count - 1 })}>-</button>
              <span>{count}</span>
              <button onClick={() => this.setState({ count: count + 1 })}>+</button>
            </p>
          </dd>
        </dl>
      </div>  
    )
  }
  shouldComponentUpdate(nextProps, nextState) {
    if(nextState.count > 5) return false
    if(nextState.count < 1) return false
    return true
  }
}

export default Car